#Linux Makefile

#BLDTYPE = release
BLDTYPE = debug

DIR_WSC=.

#CROSS=/opt/uclibc-toolchain/ifx-lxdb-1-2/gcc-3.3.6/toolchain-mips/bin-ccache/mips-linux-
#CROSS=/opt/uclibc-toolchain/ifx-lxdb26-1.0.2/gcc-3.4.4/toolchain-mips/bin-ccache/mips-linux-
#STRIP=/opt/uclibc-toolchain/ifx-lxdb26-1.0.2/gcc-3.4.4/toolchain-mips/bin/mips-linux-strip
STRIP=strip
PWD=$(shell pwd)
export CXX = $(CROSS)g++
export CC = $(CROSS)gcc
ifeq ($(BLDTYPE),debug)
#export CXXFLAGS += -Wall -g -D_REENTRANT -D_TUDEBUGTRACE 
export CXXFLAGS += -Wall -D_REENTRANT -D_TUDEBUGTRACE  -g -Os  -I$(PWD)/../../../openssl-0.9.8g/include
#export CFLAGS += -Wall -Wnested-externs -g -D_REENTRANT -D_TUDEBUGTRACE
export CFLAGS += -Wall -Wnested-externs -D_REENTRANT -D_TUDEBUGTRACE 
else
export CXXFLAGS += -Wall -D_REENTRANT -Os
export CFLAGS += -Wall -Wnested-externs -D_REENTRANT -Os 
endif
#export LD = /opt/uclibc-toolchain/ifx-lxdb-1-3/gcc-3.3.6/toolchain-mips/bin/mips-linux-ld
#export LD = /opt/uclibc-toolchain/ifx-lxdb26-1.0.2/gcc-3.4.4/toolchain-mips/bin/mips-linux-ld
export LD=ld
export LDFLAGS = -r
#export LIBPATH =  -L/opt/uclibc-toolchain/ifx-lxdb26-1.0.2/gcc-3.4.4/toolchain-mips/lib
#export INCLUDE =  -I/opt/uclibc-toolchain/ifx-lxdb26-1.0.2/gcc-3.4.4/toolchain-mips/include

LIBS =  trace/tutrace.lib \
	slist/slist.lib \
	Portability/Portability.lib \
	UdpLib/UdpLib.lib \
	InbEap/InbEap.lib \
	InbIp/InbIp.lib \
	InbWlan/InbWlan.lib \
	UPnPILib/UPnPILib.lib \
	UPnPCpLib/UPnPCpLib.lib \
	InbUPnPCp/InbUPnPCp.lib \
	UPnPDevLib/UPnPDevLib.lib \
	InbUPnPDev/InbUPnPDev.lib \
	Transport/Transport.lib \
	StateMachine/StateMachine.lib \
	RegProtocol/RegProtocol.lib \
	MasterControl/MasterControl.lib \
	TlvBase/WscTlvBase.lib\
	WscCmd/WscCmd.lib \
	-L$(PWD)/../../../openssl-0.9.8g \
	-lpthread -lc -lssl -lcrypto 
	#-lpthread -lcurses -lc -lssl -lcrypto
ifdef STATIC_BUILD
LIBS += -static
endif


WSC_CFG_OBJ = WscCmd/WscCfg.o

default: 
	cd trace && $(MAKE)
	cd slist && $(MAKE)
	cd Portability && $(MAKE)
	cd TlvBase && $(MAKE)
	cd UdpLib && $(MAKE)
	cd InbEap && $(MAKE)
	cd InbIp && $(MAKE)
	cd InbWlan && $(MAKE)
	cd UPnPILib && $(MAKE)
	cd UPnPCpLib && $(MAKE)
	cd InbUPnPCp && $(MAKE)
	cd UPnPDevLib && $(MAKE)
	cd InbUPnPDev && $(MAKE)
	cd Transport && $(MAKE)
	cd StateMachine && $(MAKE)
	cd RegProtocol && $(MAKE)
	cd MasterControl && $(MAKE)
	cd WscCmd && $(MAKE)
	$(CXX) $(OBJS) $(LIBS) $(LIBPATH) -o wsccmd
	$(STRIP) wsccmd
	cd WscCmd && $(MAKE) WscCfg
	$(CXX) $(WSC_CFG_OBJ) -static -lc $(LIBPATH) -o wsc_cfg
	$(STRIP) wsc_cfg

clean:
	cd trace && $(MAKE) clean
	cd slist && $(MAKE) clean
	cd Portability && $(MAKE) clean
	cd TlvBase && $(MAKE) clean
	cd UdpLib && $(MAKE) clean
	cd InbEap && $(MAKE) clean
	cd InbIp && $(MAKE) clean
	cd InbWlan && $(MAKE) clean
	cd UPnPILib && $(MAKE) clean
	cd UPnPCpLib && $(MAKE) clean
	cd InbUPnPCp && $(MAKE) clean
	cd UPnPDevLib && $(MAKE) clean
	cd InbUPnPDev && $(MAKE) clean
	cd Transport && $(MAKE) clean
	cd StateMachine && $(MAKE) clean
	cd RegProtocol && $(MAKE) clean
	cd MasterControl && $(MAKE) clean
	cd WscCmd && $(MAKE) clean
	rm -f wsccmd
	rm -f wsc_cfg
install: default
	cp -f wsccmd $(PREFIX)/wsccmd; \
	cp -f wsc_cfg $(PREFIX)/wsc_cfg
	cp -f wsc_config.txt $(CONFIG_PATH)/wsc_config.txt
	cp -f default_wsc_cfg.txt $(DEFAULT_CFG)/default_wsc_cfg.txt
